package com.pakazaka.player;

import com.pakazaka.controllers.Controller;
import com.pakazaka.enums.PlayerStateType;
import com.pakazaka.simplecrawler.Core;
import static com.pakazaka.simplecrawler.Core.getInstance;
import com.pakazaka.testItemsSystem.Item;

/**
 *
 * @author Remi
 */
public class Equip {

    //using for equip, because fixed number of slots is not enough for a roguelike
    public final static int SLOT_HEAD_GLASSES = 0, SLOT_HEAD_MASK = 1, SLOT_HELMET = 2;
    public final static int SLOT_TSHIRT = 3, SLOT_TORSO_JACKET = 4, SLOT_TORSO_CLOAK = 5;
    public final static int SLOT_LEGS = 6, SLOT_BOOTS = 7, SLOT_LEFT_HAND = 9, SLOT_RIGHT_HAND = 9;
    public final static int SLOT_BACKPACK = 10;
    private final Item[] equip = new Item[11];
    private final Player hero = getInstance().getPlayer();

    public Item getEquippedItem(int slot) {
        return equip[slot];
    }

    public Item[] getEquipArray() {
        return equip;
    }

    private String getAction(Item item) {
        if (item == null) {
            return "off";
        } else {
            return "on";
        }
    }

    public void equipItem(Item item) {
        String action = "on ";
        switch (item.getWearSlot()) {
            case BOOTS:
                equip[SLOT_BOOTS] = (equip[SLOT_BOOTS] == item) ? null : item;
                action = getAction(equip[SLOT_BOOTS]);
                break;
            case HELMET:
                equip[SLOT_HELMET] = (equip[SLOT_HELMET] == item) ? null : item;
                action = getAction(equip[SLOT_HELMET]);
                break;
            case TSHIRT:
                equip[SLOT_TSHIRT] = (equip[SLOT_TSHIRT] == item) ? null : item;
                action = getAction(equip[SLOT_TSHIRT]);
                break;
        }

        Core.getInstance().getConsole().pushMessage("You put " + action + " your " + item.getName().toLowerCase());
        Core.getInstance().getInventory().setPaint(false);
        Core.getInstance().setWhereMessage("");
        Controller.setPressed(true);
        Core.getInstance().getPlayer().setState(PlayerStateType.NORMAL);

    }

    public void unequipItem(int slot) {
        equip[slot] = null;
    }

    public int getProtectionValue() {
        int protection = 0;
        for (Item equip1 : equip) {
            if (equip1 != null) {
                protection += equip1.getProtection();
            }
        }

        return protection;
    }
}
